package cn.com.cifi.mars.mapper.wrapper;

import cn.com.cifi.mars.entity.ReturnPlanVersionCoefficient;
import cn.com.cifi.mars.mapper.mars.ReturnPlanVersionCoefficientMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author: JingYuanXiang
 * @date: 2020/11/16 11:38
 */
@Component
public class ReturnPlanVersionCoefficientWrapper {

    @Autowired
    private ReturnPlanVersionCoefficientMapper returnPlanVersionCoefficientMapper;

    /**
     * 获取项目回款系数最早被回款计划使用的时间
     * @param projectCoefficientId
     * @param isDel
     * @return
     */
    public LocalDateTime selectEarliestCreateTimeByProjectCoefficientId(String projectCoefficientId,int isDel){
        QueryWrapper<ReturnPlanVersionCoefficient> queryWrapper = new QueryWrapper();
        queryWrapper.eq("project_coefficient_id",projectCoefficientId)
                .eq("is_delete", isDel)
                .orderByAsc("create_time")
                .last("limit 1");

        ReturnPlanVersionCoefficient returnPlanVersionCoefficient = returnPlanVersionCoefficientMapper.selectOne(queryWrapper);
        if(null == returnPlanVersionCoefficient){
            return null;
        }else {
            return returnPlanVersionCoefficient.getCreateTime();
        }
    }

    public List<ReturnPlanVersionCoefficient> selectListByReturnPlanVersionId(String returnPlanVersionId,int isDel) {
        QueryWrapper<ReturnPlanVersionCoefficient> queryWrapper = new QueryWrapper();
        queryWrapper.eq("return_plan_version_id",returnPlanVersionId)
                .eq("is_delete", isDel);

        return returnPlanVersionCoefficientMapper.selectList(queryWrapper);
    }
}
